package com.neymar.controller;


import com.neymar.entity.Applicant;
import com.neymar.logEnum.ObjectionTypeEnum;
import com.neymar.logEnum.OperationTypeEnum;
import com.neymar.service.ApplicantService;
import com.neymar.service.LogService;
import com.neymar.vo.R;
import com.neymar.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 求职者表 前端控制器
 * </p>
 *
 * @author neymar
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/applicant")
@Api(tags = {"用户详细信息操作接口"})
public class ApplicantController {

    @Autowired
    ApplicantService applicantService;

    @Autowired
    private LogService logService;

    @GetMapping("/ydgm")
    public String ydgm() {
        return "远大光明";
    }

    @ApiOperation("增加用户的详细信息")
    @PostMapping("/add/{userId}")
    public R save(@RequestBody Applicant applicant,
                  @PathVariable("userId") String userId) {
        applicant.setApplicantBirthday(new Date());
        int flag = applicantService.save(applicant);
        if (flag != 0) {
            logService.save(userId, 1, 5);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("查询用户的详细信息")
    @GetMapping("/find/{userId}/{operatorId}")
    public R findApplicantById(@PathVariable("userId") String userId,
                               @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 5);
        return R.ok(applicantService.findApplicantById(userId));
    }

    @ApiOperation("更新用户的详细信息")
    @PutMapping("/update")
    public R updateUserById(@RequestBody Applicant applicant) {
        int flag = applicantService.updateApplicantById(applicant);
        if (flag != 0) {
            logService.save(applicant.getUserId(), 3, 5);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("删除用户的详细信息")
    @DeleteMapping("/delete/{userId}")
    public R deleteUserById(@PathVariable("userId") String userId) {
        int flag = applicantService.deleteApplicantById(userId);
        if (flag != 0) {
            logService.save(userId, 2, 5);

            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("查看所有用户的状态")
    @GetMapping("/showStatusInfo/{operatorId}")
    public R showStatusInfo(@PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 5);
        return R.ok(applicantService.showStatusInfo());
    }

    @ApiOperation("所有用户的男女比例")
    @GetMapping("/showGenderInfo/{operatorId}")
    public R showGenderInfo(@PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 5);
        return R.ok(applicantService.showGenderInfo());
    }

    @ApiOperation("用户的受教育程度分类信息")
    @GetMapping("/showEduInfo/{operatorId}")
    public R showEduInfo(@PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 5);
        return R.ok(applicantService.showEduInfo());
    }


}

